package com.boot.mall.product.service.impl;

import com.boot.mall.product.entity.AttrEntity;
import com.boot.mall.product.service.AttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.boot.common.utils.PageUtils;
import com.boot.common.utils.Query;

import com.boot.mall.product.dao.AttrAttrgroupRelationDao;
import com.boot.mall.product.entity.AttrAttrgroupRelationEntity;
import com.boot.mall.product.service.AttrAttrgroupRelationService;


@Service("attrAttrgroupRelationService")
public class AttrAttrgroupRelationServiceImpl extends ServiceImpl<AttrAttrgroupRelationDao, AttrAttrgroupRelationEntity> implements AttrAttrgroupRelationService {

    @Autowired
    private AttrService attrService;

    // 根据分组的id查询分组的详细属性信息
    @Override
    public List<AttrEntity> getRelationAttrByGroupId(String attrGroupId) {
        // 根据分组的id在分组与属性联系表中查询分组的详细信息，获取属性的id
        List<AttrAttrgroupRelationEntity> attrGroups = baseMapper.selectList(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_group_id", attrGroupId));
        // 遍历分组
        for (AttrAttrgroupRelationEntity attrGroup : attrGroups) {
            // 根据属性id查询属性的完整信息
            List<AttrEntity> attrs = attrService.list(new QueryWrapper<AttrEntity>().eq("attr_id", attrGroup.getAttrId()));
            return attrs;
        }
        return null;
    }
}